package com.jk.admin.controller;

import com.jk.admin.entity.ProductSeckill;
import com.jk.admin.service.SellsService;
import com.jk.admin.utils.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class SellsController {
    @Autowired
    private SellsService sellsService;

    @RequestMapping("getSells")
    public List<ProductSeckill> getSells(){
        return sellsService.getSells();
    }
    @RequestMapping("delSells")
    public void delSells(Integer id){
         sellsService.delSells(id);
    }
    @RequestMapping("addSells")
    public void addSells(ProductSeckill pro,HttpServletRequest request){
        String img = (String) request.getSession().getAttribute("img");
        pro.setI_img(img);
        System.out.println(img+"-----s----ss------s-----");
        sellsService.addSells(pro);
    }

    @RequestMapping("upload11")
    public Map upload(MultipartFile img, HttpServletRequest request) throws Exception{
        String upload2oss = OSSUtil.upload2oss(img);
        System.out.println(upload2oss);
        request.getSession().setAttribute("img", upload2oss);
        Map map=new HashMap<>();
        map.put("upload2oss", upload2oss);
        return map;
    }
}
